package com.allwayz.controller;

import com.allwayz.domain.CommonResult;
import com.allwayz.domain.Order;
import com.allwayz.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author allwayz
 */
@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {
    @Resource
    private OrderService orderService;

    @GetMapping()
    public CommonResult create(Order order) {
        orderService.create(order);
        return new CommonResult(200,"订单创建成功");
    }

    @GetMapping("/all")
    public CommonResult getAllOrder(){
        List<Order> orderList = orderService.getAllOrder();
        if(orderList.size() != 0){
            return new CommonResult(200,"查询成功",orderList);
        }else {
            return new CommonResult(404,"无对应记录");
        }
    }
}
